package cn.xopencode.scoreservice.provider.demand;

import cn.xopencode.common.framework.validator.InEnum;
import cn.xopencode.common.framework.vo.CommonResult;
import cn.xopencode.score.api.enums.innovate.SuggestScoreEnum;
import cn.xopencode.score.api.rpc.ScoreRpc;
import cn.xopencode.score.api.rpc.demand.dto.ScoreDetailsRespDTO;
import cn.xopencode.score.api.rpc.demand.dto.ScoreReqDTO;
import cn.xopencode.score.api.rpc.demand.dto.ScoreRespDTO;
import cn.xopencode.scoreservice.service.demand.ScoreService;
import cn.xopencode.securityservice.enums.suggest.SuggestLevelEnum;
import cn.xopencode.securityservice.rpc.suggest.dto.SuggestCreateReqDTO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

import static cn.xopencode.common.framework.vo.CommonResult.success;

/**
 * 安全活动与技能比武情况 Rpc 实现
 */
@DubboService(version = "${dubbo.provider.ScoreRpc.version}")
public class ScoreRpcProviderImpl implements ScoreRpc {
    @Autowired
    private ScoreService scoreService;
//    @Override  //传入员工的编号
//    public CommonResult<ScoreDetailsRespDTO> getScoreDetails(ScoreReqDTO scoreReqDTO) {
//        return success(scoreService.getDetailsScore(scoreReqDTO));
//    }

    @Override
    public CommonResult<ScoreDetailsRespDTO> getScoreDetails(String empId) {
        return success(scoreService.getDetailsScore(empId));
    }

    @Override
    public CommonResult<List<ScoreRespDTO>> getScoreList() {
        System.out.println("aaaaaaa");
//        System.out.println("scoreService.pageScore():"+scoreService.pageScore());

        return success(scoreService.pageScore());
    }

    @Override
    public CommonResult<List<ScoreRespDTO>> getDateScoreList(ScoreReqDTO scoreReqDTO) {
        return success(scoreService.pageScore());
    }


    @Override
    public Double addSuggestScore(@Valid SuggestCreateReqDTO createDTO) {
        @NotNull(message = "建议级别不能为空")
        @InEnum(value = SuggestLevelEnum.class, message = "建议级别必须是 {value}")
        Integer suggestLevel = createDTO.getSuggestLevel();
        Double resultScore = null;

        for (SuggestLevelEnum level : SuggestLevelEnum.values()) {
            if (createDTO.getSuggestLevel() == level.getLevel()) {
                for (SuggestScoreEnum score : SuggestScoreEnum.values()) {
                    if (level.getName().equals(score.getName())) {
                        System.out.println("name:" + score.getName());
                        System.out.println("getScore:" + score.getScore());
                        resultScore = scoreService.addSuggestScore("1001", score.getScore());
                    }
                }
            }
        }

        System.out.println("resultScore:" + resultScore);
        return resultScore;
    }
}
